package edu.mju.security.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * 配置密码处理
 * 使用BCrypt密码处理，也可自行配置MD5
 */
@Component
public class DefaultPasswordUtils implements PasswordEncoder {
    public DefaultPasswordUtils() {
        this(-1);
    }

    /**
     * @param strength the log rounds to use, between 4 and 31
     */
    public DefaultPasswordUtils(int strength) {

    }

    /**
     * 加密
     */
    @Override
    public String encode(CharSequence charSequence) {
        return new BCryptPasswordEncoder().encode(charSequence);
    }

    /**
     * 比对
     */
    @Override
    public boolean matches(CharSequence charSequence, String s) {
        return new BCryptPasswordEncoder().matches(charSequence,s);
    }
}
